package com.zodiac.alioth.common.model.vo;

import com.zodiac.alioth.common.enums.ApiRespCodeEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;


/**
 * @author zodiac
 */
@Data
@NoArgsConstructor
public class ApiResponse<T> implements Serializable {

    private static final long serialVersionUID = 1340563394201259857L;

    private boolean success;

    private Integer errorCode;

    private String errorMsg;

    private T result;

    private Object[] arguments;

    public ApiResponse(Integer errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public static <T> ApiResponse<T> getSuccessResult(T v) {
        ApiResponse<T> result = new ApiResponse<>();
        result.setSuccess(true);
        result.setErrorCode(ApiRespCodeEnum.SUCCESS.getCode());
        result.setErrorMsg(ApiRespCodeEnum.SUCCESS.getDesc());
        result.setResult(v);
        return result;
    }

    public static <T> ApiResponse<T> getResult(Integer errorCode, String msg) {
        ApiResponse<T> result = new ApiResponse<>(errorCode, msg);
        result.setSuccess(false);
        return result;
    }

    public static <T> ApiResponse<T> getResult(ApiRespCodeEnum apiRespCodeEnum) {
        ApiResponse<T> result = new ApiResponse<T>();
        result.setSuccess(false);
        result.setErrorCode(apiRespCodeEnum.getCode());
        result.setErrorMsg(apiRespCodeEnum.getDesc());
        return result;
    }

}

